package com.example.r2dbc.service;

import com.example.r2dbc.dao.DemoUserDao;
import com.example.r2dbc.entity.DemoUser;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author renyr
 * @version 0.1
 * @date 2021/1/12 11:01
 * @since 0.1
 */
@Service
public class DemoUserService {
    @Resource
    private DemoUserDao userDao;

    public Mono<DemoUser> saveUser(DemoUser user) {
        user.setCreateTime(System.currentTimeMillis());
        return userDao.save(user);
    }

    public Flux<DemoUser> saveUsers(List<DemoUser> users) {
        return userDao.saveAll(users);
    }

    public Mono<Void> deleteUser(Integer userId) {
        return userDao.deleteById(userId);
    }

    public Flux<DemoUser> findUserList() {
        return userDao.findAll();
    }

    public Mono<DemoUser> findUserOne(Integer userId) {
        return userDao.findById(userId);
    }

}
